package com.example.hello.config;

import io.minio.MinioClient;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class ObjectStorageConfig {

    @Value("${object.storage.endpoint}")
    private String endpoint;

    @Value("${object.storage.access-key}")
    private String accessKey;

    @Value("${object.storage.secret-key}")
    private String secretKey;

    @Bean
    public MinioClient minioClient() {
        // 创建自定义的 OkHttpClient，增加超时设置
        OkHttpClient httpClient = new OkHttpClient.Builder()
                .connectTimeout(30, TimeUnit.SECONDS)
                .writeTimeout(30, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .build();

        // 创建 MinioClient 实例
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .httpClient(httpClient)
                .build();
    }
} 